package breadbox.pastry;

import java.io.IOException;

/**
 * This interface should export the functions
 * required by the application to send messages.
 * @author Brian
 *
 */

public interface Node {
	
	/**
	 * 
	 * @return errorCode
	 */
	int join();
	
	/**
	 * @return errorCode
	 */
	int open();
	
	/**
	 * @return errorCode
	 */
	int close();
	
	/**
	 * Relates the application to the node to allow it
	 * to call back when messages are received.
	 * @param app
	 */
	void register(Application app);
	
	/** 
	 * Removes relation to application/will also close node
	 * if not already done.
	 */
	void unregister();
	
	/**
	 * Method will consult routing table and route 
	 * message to next closest Id. For client use only.
	 * @return errorCode
	 */
	int route(Message m);
	
	/**
	 * Method will attempt to deliver message to
	 * the specified IP. For client use only.
	 * @return errorCode
	 */
	int send(Message m, Connection c) throws IOException;
	
	ID getNodeId();
}
